package Chatnetwork;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class ClientUser {
    public static void main(String[] args) throws IOException {
//        final String server_address = "localhost";
        final String server_address = "192.168.7.35";
        final int server_port = 1234;
        Socket socket = new Socket(server_address, server_port);
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        Scanner scanner = new Scanner(System.in);
        Thread thread = new Thread(() -> {
            String userInput;
            while ((userInput = scanner.nextLine()) != null) {
                out.println(userInput);
            }
        });
        thread.start();
        String serverResponse;
        while ((serverResponse = in.readLine()) != null) {
            System.out.println("接收到服务器端的message是" + serverResponse);
        }
    }
}
